package com.easy.component.component.header;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.easy.component.R;

/**
 * 描述: {描述}
 * 作者:jack-song
 * 创建日期: 2017/11/2 10:50
 * 修改日期: 2017/11/2
 * 版本: {版本}
 */
public class EasyHeaderBuilder extends EaseyBaseHeader {
    private Activity context;

    public EasyHeaderBuilder(Activity context) {
        this.context = context;
        setContainerView(context.findViewById(R.id.ll_header));
    }

    public EasyHeaderBuilder(Activity context, View containerView) {
        this.context = context;
        setContainerView(containerView.findViewById(R.id.ll_header));
    }

    /**
     * 添加只有返回按钮的左侧布局
     */
    public EasyHeaderBuilder addLeftImageBackView() {
        addLeftContainerView(LayoutInflater.from(context).inflate(R.layout.easy_left_image_header, null));
        return this;
    }

    /**
     * 添加右侧文本
     */
    public EasyHeaderBuilder addRigthTextView() {
        addRigthContainerView(LayoutInflater.from(context).inflate(R.layout.easy_rigth_text_header, null));
        return this;
    }

    /**
     * 设置title
     *
     * @param text
     */
    public EasyHeaderBuilder setTitle(CharSequence text) {
        ((TextView) containerView.findViewById(R.id.tv_title)).setText(text);
        return this;
    }

    /**
     * 设置title
     *
     * @param resid
     */
    public EasyHeaderBuilder setTitle(int resid) {
        ((TextView) containerView.findViewById(R.id.tv_title)).setText(resid);
        return this;
    }

    /**
     * 添加左侧按钮返回事件
     */
    public EasyHeaderBuilder addLeftImageBackListener(final View.OnClickListener onClickListener) {
        ((LinearLayout) containerView.findViewById(R.id.ll_left)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != onClickListener) {
                    onClickListener.onClick(view);
                }
            }
        });
        return this;
    }

    /**
     * 设置左侧按钮图片
     *
     * @param resid
     */
    public EasyHeaderBuilder setLeftImageBackBackground(int resid) {
        ((ImageView) containerView.findViewById(R.id.btn_left)).setImageResource(resid);
        return this;
    }

    /**
     * 设置右侧文字
     *
     * @param text
     */
    public EasyHeaderBuilder setRigthText(CharSequence text) {
        ((TextView) containerView.findViewById(R.id.tv_rigth)).setText(text);
        return this;

    }

    /**
     * 设置右侧文字
     *
     * @param resid
     */
    public EasyHeaderBuilder setRigthText(int resid) {
        ((TextView) containerView.findViewById(R.id.tv_rigth)).setText(resid);
        return this;
    }
    /**
     * 设置右侧文字
     *
     * @param
     */
    public String getRigthText() {
        return ((TextView) containerView.findViewById(R.id.tv_rigth)).getText().toString();
    }

    /**
     * 添加左侧按钮返回事件
     */
    public EasyHeaderBuilder addRigthTextListener(final View.OnClickListener onClickListener) {
        ((TextView) containerView.findViewById(R.id.tv_rigth)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != onClickListener) {
                    onClickListener.onClick(view);
                }
            }
        });
        return this;
    }

    public EasyHeaderBuilder setContainerBackgroundResource(int resid) {
        rlHeaderContainerView.setBackgroundResource(resid);
        return this;
    }

    public EasyHeaderBuilder isShowHeader(boolean isShow) {
        if (isShow) {
            containerView.setVisibility(View.VISIBLE);
        } else {
            containerView.setVisibility(View.GONE);
        }
        return this;
    }
}
